--[[

     Licensed under GNU General Public License v2
      * (c) 2013, Luca CPZ

--]]

local helpers  = require("lain.helpers")
local wibox    = require("wibox")


local function factory(args)
    args           = args or {}

    local fan     = { widget = args.widget or wibox.widget.textbox() }
    local timeout  = args.timeout or 5
    local pump_load_cmd = "/home/ethan/miniconda3/envs/nzxt_test/bin/liquidctl status | grep 'Pump duty' | awk '{print $4}'"
    local fan_load_cmd = "/home/ethan/miniconda3/envs/nzxt_test/bin/liquidctl status | grep 'Fan duty' | awk '{print $4}'"
    local settings = args.settings or function() end

    function fan.update()
        pump_f, err = io.popen(pump_load_cmd)
        pump_load = string.sub(pump_f:read(), 1) or "N/A"

        fan_f, err = io.popen(fan_load_cmd)
        fan_load = string.sub(fan_f:read(), 1) or "N/A"

        widget = fan.widget
        settings()
    end

    helpers.newtimer("thermal", timeout, fan.update)

    return fan
end

return factory
